package com.sstir.doctor.service;

/**
 * @ClassName MyWebSocketServer
 * @Description
 * @Author hanjunjun
 * @Date 2021/1/14 14:54
 */
/*@Component
@Slf4j
@ServerEndpoint("/gameover")
public class MyWebSocketServer {

    private static Map<String, Session> clients = new ConcurrentHashMap<>();

    @OnOpen
    public void onOpen(Session session){
        log.info("新的客户端加入了：{}", session.getId());
        String userId = SnowflakeIdWorker.generateId();
        session.getUserProperties().put("userId", userId);
        clients.put(userId, session);
    }

    *//**
     * 客户端关闭
     * @param session session
     *//*
    @OnClose
    public void onClose(Session session) {
        log.info("有用户断开了, id为:{}", session.getId());
        //将掉线的用户移除在线的组里
        clients.remove(session.getId());
    }

    *//**
     * 发生错误
     * @param throwable e
     *//*
    @OnError
    public void onError(Throwable throwable) {
        throwable.printStackTrace();
    }

    *//**
     * 收到客户端发来消息
     * @param message  消息对象
     *//*
    @OnMessage
    public void onMessage(String message) {
        log.info("服务端收到客户端发来的消息: {}", message);
    }

    *//**
     * 发送消息
     * @param message 消息内容
     *//*
    private void sendMessage(String message, String userId) {
        for (Map.Entry<String, Session> sessionEntry : clients.entrySet()) {
            if (userId.equals(sessionEntry.getKey())){
                sessionEntry.getValue().getAsyncRemote().sendText(message);
                break;
            }
        }
    }



}*/
